home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / PowerPlant / Everything / CModalCheckboxes.cp < prev    next >
Encoding:
Text File  |  1998-10-11  |  9.2 KB  |  469 lines  |  [TEXT/CWIE]

  1. // CModalCheckboxes.cp -- dialog methods
  2.  
  3. #include "CModalCheckboxes.h"
  4.  
  5. #include <UEnvironment.h>
  6. #include <UReanimator.h>
  7. #include <URegistrar.h>
  8. #include <LStream.h>
  9. #include <LTabGroup.h>
  10. #include <LPushButton.h>
  11. #include <LAMPushButtonImp.h>
  12. #include <LGAPushButtonImp.h>
  13. #include <LCheckBox.h>
  14. #include <LAMControlImp.h>
  15. #include <LGACheckboxImp.h>
  16. #include <LDisclosureTriangle.h>
  17. #include <LGADisclosureTriangleImp.h>
  18. #include <LStaticText.h>
  19. #include <LAMStaticTextImp.h>
  20. #include <LGAStaticTextImp.h>
  21. #include <LTextGroupBox.h>
  22. #include <LAMControlViewImp.h>
  23. #include <LGATextGroupBoxImp.h>
  24. #include <CustomControls.h>
  25. #include <LToggleButton.h>
  26. #include <LBevelButton.h>
  27. #include <LAMBevelButtonImp.h>
  28. #include <LGABevelButtonImp.h>
  29. #include <CTextUtils.h>
  30.  
  31. #include "DModalCheckboxesData.h"
  32. #include "EverythingCmds.h"
  33. #include <PP_Messages.h>
  34.  
  35. const MessageT    msgStandard    = 'Stad';
  36. const MessageT    msgXx    = 'Xx  ';
  37. const MessageT    msgLR    = 'LR  ';
  38. const MessageT    msgLR2    = 'LR2 ';
  39. const MessageT    msgLR3    = 'LR3 ';
  40. const MessageT    msgLR4    = 'LR4 ';
  41. const MessageT    msgCheckbox    = 'Chex';
  42. const MessageT    msgCheckbox2    = 'Che2';
  43. const MessageT    msgNext    = 'Next';
  44. const MessageT    msgNext2    = 'Nex2';
  45.  
  46. #define PPob_ModalCheckboxesID    209
  47. #define RidL_ModalCheckboxesID    209
  48.  
  49. Boolean        CModalCheckboxes::sIsRegistered = false;
  50.  
  51. //----------
  52. CModalCheckboxes*        CModalCheckboxes::CreateModalCheckboxes (
  53.     LCommander*        inSuperCommander,
  54.     CommandT        inCommand,
  55.     DModalCheckboxesData*        inData)
  56. {
  57.     if (!sIsRegistered) {
  58.         RegisterClass ();
  59.     }
  60.     CModalCheckboxes*        dlog;
  61.     dlog = ((CModalCheckboxes *)LWindow::CreateWindow(PPob_ModalCheckboxesID, inSuperCommander));
  62.     dlog->mCommand = inCommand;
  63.     dlog->SetFromData (inData);
  64.  
  65.     return dlog;
  66. }
  67.  
  68. //----------
  69. #define    RegisterClasses(AbstractClass,AMImpClass,GAImpClass)    \
  70.     RegisterClass_(AbstractClass);    \
  71.     if (useAppearance) {    \
  72.         RegisterClassID_(AMImpClass, AbstractClass::imp_class_ID);    \
  73.     } else {    \
  74.         RegisterClassID_(GAImpClass, AbstractClass::imp_class_ID);    \
  75.     }
  76.  
  77. //----------
  78. void    CModalCheckboxes::RegisterClass ()
  79. {
  80.     Boolean        useAppearance = UEnvironment::HasFeature (env_HasAppearance);
  81.  
  82.     RegisterClass_(CModalCheckboxes);
  83.  
  84.     // register the pane classes we use
  85.     RegisterClasses (LPushButton, LAMPushButtonImp, LGAPushButtonImp);
  86.     RegisterClasses (LCheckBox, LAMControlImp, LGACheckboxImp);
  87.     RegisterClasses (LDisclosureTriangle, LAMControlImp, LGADisclosureTriangleImp);
  88.     RegisterClasses (LStaticText, LAMStaticTextImp, LGAStaticTextImp);
  89.     RegisterClasses (LTextGroupBox, LAMControlViewImp, LGATextGroupBoxImp);
  90.     RegisterClasses (CCheckBox, CustomControlImp, CustomControlImp);
  91.     RegisterClass_(LToggleButton);
  92.     RegisterClasses (LBevelButton, LAMBevelButtonImp, LGABevelButtonImp);
  93.  
  94.     sIsRegistered = true;
  95. }
  96.  
  97. //----------
  98. CModalCheckboxes::CModalCheckboxes (
  99.     LStream*    inStream)
  100.     : LGADialog (inStream)
  101. {
  102.     mData = nil;
  103. }
  104.  
  105. //----------
  106. CModalCheckboxes::~CModalCheckboxes()
  107. {
  108.     delete mData;
  109. }
  110.  
  111. //----------
  112. //    This member function gets called once the containment hierarchy that contains
  113. //    this pane has been built. It gives us a chance to get data members for
  114. //    interesting subviews, and to do other operations now that our subviews exist.
  115. void    CModalCheckboxes::FinishCreateSelf()
  116. {
  117.     LGADialog::FinishCreateSelf();
  118.  
  119.     mOKButton = (LPushButton*) FindPaneByID ('OK  ');
  120.  
  121.     mStandardCheck = (LCheckBox*) FindPaneByID ('Stad');
  122.  
  123.     mXxCheck = (LDisclosureTriangle*) FindPaneByID ('Xx  ');
  124.  
  125.     mLRCheck = (CCheckBox*) FindPaneByID ('LR  ');
  126.  
  127.     mLR2Check = (CCheckBox*) FindPaneByID ('LR2 ');
  128.  
  129.     mLR3Check = (LToggleButton*) FindPaneByID ('LR3 ');
  130.  
  131.     mLR4Check = (LToggleButton*) FindPaneByID ('LR4 ');
  132.  
  133.     mCheckboxCheck = (CCheckBox*) FindPaneByID ('Chex');
  134.  
  135.     mCheckbox2Check = (LBevelButton*) FindPaneByID ('Che2');
  136.  
  137.     mNextCheck = (LBevelButton*) FindPaneByID ('Next');
  138.  
  139.     mNext2Check = (LBevelButton*) FindPaneByID ('Nex2');
  140.  
  141.  
  142.     UReanimator::LinkListenerToControls(this, this, RidL_ModalCheckboxesID);
  143.         // the purpose is to "connect" self to whatever controls
  144.         // that we want to "listen" to
  145.  
  146. // any additional initialization for your dialog:
  147.  
  148. }
  149.  
  150. //----------
  151. void    CModalCheckboxes::SetFromData (
  152.     DModalCheckboxesData*        inData)
  153. {
  154.     mData = inData;
  155.     mData->AddListener (this);
  156.  
  157.     mStandardCheck->SetValue (mData->GetStandard4 ());
  158.     mXxCheck->SetValue (mData->GetXx2 ());
  159.     mLRCheck->SetValue (mData->GetLR5 ());
  160.     mLR2Check->SetValue (mData->GetLR6 ());
  161.     mLR3Check->SetValue (mData->GetLR7 ());
  162.     mLR4Check->SetValue (mData->GetLR8 ());
  163.     mCheckboxCheck->SetValue (mData->GetCheckbox3 ());
  164.     mCheckbox2Check->SetValue (mData->GetCheckbox4 ());
  165.     mNextCheck->SetValue (mData->GetNext3 ());
  166.     mNext2Check->SetValue (mData->GetNext4 ());
  167. }
  168.  
  169. //----------
  170. DModalCheckboxesData*        CModalCheckboxes::GetData ()
  171. {
  172.  
  173.     return mData;
  174. }
  175.  
  176. //----------
  177. void    CModalCheckboxes::DataChanged (
  178.     long        inDataID)
  179. {
  180.     StopListening ();
  181.  
  182.     if (inDataID == idStandard4) {
  183.         mStandardCheck->SetValue (mData->GetStandard4 ());
  184.     }
  185.     if (inDataID == idXx2) {
  186.         mXxCheck->SetValue (mData->GetXx2 ());
  187.     }
  188.     if (inDataID == idLR5) {
  189.         mLRCheck->SetValue (mData->GetLR5 ());
  190.     }
  191.     if (inDataID == idLR6) {
  192.         mLR2Check->SetValue (mData->GetLR6 ());
  193.     }
  194.     if (inDataID == idLR7) {
  195.         mLR3Check->SetValue (mData->GetLR7 ());
  196.     }
  197.     if (inDataID == idLR8) {
  198.         mLR4Check->SetValue (mData->GetLR8 ());
  199.     }
  200.     if (inDataID == idCheckbox3) {
  201.         mCheckboxCheck->SetValue (mData->GetCheckbox3 ());
  202.     }
  203.     if (inDataID == idCheckbox4) {
  204.         mCheckbox2Check->SetValue (mData->GetCheckbox4 ());
  205.     }
  206.     if (inDataID == idNext3) {
  207.         mNextCheck->SetValue (mData->GetNext3 ());
  208.     }
  209.     if (inDataID == idNext4) {
  210.         mNext2Check->SetValue (mData->GetNext4 ());
  211.     }
  212.  
  213.     StartListening ();
  214. }
  215.  
  216. //----------
  217. void    CModalCheckboxes::ListenToMessage (
  218.     MessageT    inMessage,
  219.     void        *ioParam)
  220. {
  221.     switch (inMessage) {
  222.     case msg_OK:
  223.             GetSuperCommander()->ProcessCommand(-mCommand, this);
  224.         break;
  225.  
  226.     case msg_Cancel:
  227.             DoClose();
  228.         break;
  229.  
  230.     case msgDataChanged:
  231.             DataChanged ((long)ioParam);
  232.         break;
  233.  
  234.     case msgStandard:
  235.             mData->SetStandard4 (mStandardCheck->GetValue ());
  236.         break;
  237.  
  238.     case msgXx:
  239.             mData->SetXx2 (mXxCheck->GetValue ());
  240.         break;
  241.  
  242.     case msgLR:
  243.             mData->SetLR5 (mLRCheck->GetValue ());
  244.         break;
  245.  
  246.     case msgLR2:
  247.             mData->SetLR6 (mLR2Check->GetValue ());
  248.         break;
  249.  
  250.     case msgLR3:
  251.             mData->SetLR7 (mLR3Check->GetValue ());
  252.         break;
  253.  
  254.     case msgLR4:
  255.             mData->SetLR8 (mLR4Check->GetValue ());
  256.         break;
  257.  
  258.     case msgCheckbox:
  259.             mData->SetCheckbox3 (mCheckboxCheck->GetValue ());
  260.         break;
  261.  
  262.     case msgCheckbox2:
  263.             mData->SetCheckbox4 (mCheckbox2Check->GetValue ());
  264.         break;
  265.  
  266.     case msgNext:
  267.             mData->SetNext3 (mNextCheck->GetValue ());
  268.         break;
  269.  
  270.     case msgNext2:
  271.             mData->SetNext4 (mNext2Check->GetValue ());
  272.         break;
  273.  
  274.  
  275.     default:
  276.           ; // do something
  277.         break;
  278.     }
  279. }
  280.  
  281. //----------
  282. Boolean        CModalCheckboxes::ObeyCommand (
  283.     CommandT    inCommand,
  284.     void*        ioParam)
  285. {
  286.     Boolean        cmdHandled = true;
  287.  
  288.     if (inCommand < 0) {
  289.         // modal dialog has finished
  290.  
  291.         switch (-inCommand) {
  292.         }
  293.  
  294.     } else {
  295.         switch (inCommand) {
  296.  
  297.         default:
  298.                 cmdHandled = LGADialog::ObeyCommand(inCommand, ioParam);
  299.             break;
  300.         }
  301.     }
  302.  
  303.     return cmdHandled;
  304. }
  305.  
  306. //----------
  307. void    CModalCheckboxes::FindCommandStatus (
  308.     CommandT    inCommand,
  309.     Boolean        &outEnabled,
  310.     Boolean        &outUsesMark,
  311.     Char16        &outMark,
  312.     Str255        outName)
  313. {
  314.     outUsesMark = false;
  315.  
  316.     switch (inCommand) {
  317.  
  318.     // +++ Add cases here for the commands you handle
  319.  
  320.     default:
  321.             LGADialog::FindCommandStatus(inCommand, outEnabled,
  322.                                             outUsesMark, outMark, outName);
  323.         break;
  324.     }
  325. }
  326.  
  327. // following functions will be obsoleted
  328. // retained only for backwards compatibility
  329. //----------
  330. Boolean
  331. CModalCheckboxes::GetStandardChoice()
  332. {
  333.     return mStandardCheck->GetValue();
  334. }
  335.  
  336. void
  337. CModalCheckboxes::SetStandardChoice (
  338.     Boolean        inChoice)
  339. {
  340.     mStandardCheck->SetValue (inChoice);
  341. }
  342.  
  343. //----------
  344. Boolean
  345. CModalCheckboxes::GetXxChoice()
  346. {
  347.     return mXxCheck->GetValue();
  348. }
  349.  
  350. void
  351. CModalCheckboxes::SetXxChoice (
  352.     Boolean        inChoice)
  353. {
  354.     mXxCheck->SetValue (inChoice);
  355. }
  356.  
  357. //----------
  358. Boolean
  359. CModalCheckboxes::GetLRChoice()
  360. {
  361.     return mLRCheck->GetValue();
  362. }
  363.  
  364. void
  365. CModalCheckboxes::SetLRChoice (
  366.     Boolean        inChoice)
  367. {
  368.     mLRCheck->SetValue (inChoice);
  369. }
  370.  
  371. //----------
  372. Boolean
  373. CModalCheckboxes::GetLR2Choice()
  374. {
  375.     return mLR2Check->GetValue();
  376. }
  377.  
  378. void
  379. CModalCheckboxes::SetLR2Choice (
  380.     Boolean        inChoice)
  381. {
  382.     mLR2Check->SetValue (inChoice);
  383. }
  384.  
  385. //----------
  386. Boolean
  387. CModalCheckboxes::GetLR3Choice()
  388. {
  389.     return mLR3Check->GetValue();
  390. }
  391.  
  392. void
  393. CModalCheckboxes::SetLR3Choice (
  394.     Boolean        inChoice)
  395. {
  396.     mLR3Check->SetValue (inChoice);
  397. }
  398.  
  399. //----------
  400. Boolean
  401. CModalCheckboxes::GetLR4Choice()
  402. {
  403.     return mLR4Check->GetValue();
  404. }
  405.  
  406. void
  407. CModalCheckboxes::SetLR4Choice (
  408.     Boolean        inChoice)
  409. {
  410.     mLR4Check->SetValue (inChoice);
  411. }
  412.  
  413. //----------
  414. Boolean
  415. CModalCheckboxes::GetCheckboxChoice()
  416. {
  417.     return mCheckboxCheck->GetValue();
  418. }
  419.  
  420. void
  421. CModalCheckboxes::SetCheckboxChoice (
  422.     Boolean        inChoice)
  423. {
  424.     mCheckboxCheck->SetValue (inChoice);
  425. }
  426.  
  427. //----------
  428. Boolean
  429. CModalCheckboxes::GetCheckbox2Choice()
  430. {
  431.     return mCheckbox2Check->GetValue();
  432. }
  433.  
  434. void
  435. CModalCheckboxes::SetCheckbox2Choice (
  436.     Boolean        inChoice)
  437. {
  438.     mCheckbox2Check->SetValue (inChoice);
  439. }
  440.  
  441. //----------
  442. Boolean
  443. CModalCheckboxes::GetNextChoice()
  444. {
  445.     return mNextCheck->GetValue();
  446. }
  447.  
  448. void
  449. CModalCheckboxes::SetNextChoice (
  450.     Boolean        inChoice)
  451. {
  452.     mNextCheck->SetValue (inChoice);
  453. }
  454.  
  455. //----------
  456. Boolean
  457. CModalCheckboxes::GetNext2Choice()
  458. {
  459.     return mNext2Check->GetValue();
  460. }
  461.  
  462. void
  463. CModalCheckboxes::SetNext2Choice (
  464.     Boolean        inChoice)
  465. {
  466.     mNext2Check->SetValue (inChoice);
  467. }
  468.  
  469.